package com.myosw.service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.myosw.solr.FilterKeyword;

import com.myosw.dao.FilterDao;
import com.myosw.entity.PageShow;
import com.myosw.pojo.Filter;
import com.myosw.pojo.Filterlog;
import com.myosw.pojo.Urls;

public class FilterService 
{
		public boolean save(Filter filter)
		{
			boolean r = filter.save()>0?true:false;
			_setlog(filter);//日志扫描
			return r;
			
		}
		
		public PageShow getFilters(int page,int size) 
		{
			Filter bean = new Filter();
			List<Filter> list = (List<Filter>) bean.list(page, size);
			return new PageShow(list, page, size, bean.totalCount());
			
		}
		
		public PageShow getFilterslog(int page,int size) 
		{
			Filterlog bean = new Filterlog();
			
			List<Filterlog> list = (List<Filterlog>) bean.list(page, size);
			return new PageShow(list, page, size, bean.totalCount());
			
		}
		
		public List<Filterlog> getlogChange(long filterid) 
		{
			return filterDao.getlogChange(filterid);
		}
		
		public PageShow getFilterslog(int page,int size,long filterid) 
		{
	
			return new PageShow(filterDao.getlogList(page, size, filterid), page, size, filterDao.getlogCount(filterid));
			
		}
		
		private void _setlog(Filter filter) 
		{
			Filter bean= new Filter();
			Filterlog filterlog = new Filterlog();
			filterlog.setFilter(filter.getId());
			filterlog.setCount(FilterKeyword.getcount(filter.getKeyword()));//总数
			filterlog.setNewcount((int) (filterlog.getCount()-filter.getCount()));//新添加数
			filterlog.setUpdatetime(new Timestamp(new Date().getTime()));
			filterlog.save();
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("count", filterlog.getCount());
			map.put("newcount", filterlog.getNewcount());
			map.put("updatetime", filterlog.getUpdatetime());
			bean.update(map , filter.getId());
			
		}
		
		FilterDao filterDao = new FilterDao();
		
}
